import config from '@/common/config.js';

let app = {};

/*
 * 检查token 
 * @return {String} token
 **/
app.checkToken = function(token){
	// 无token时，退出登录
	if(!token){
		uni.showToast({
			title: '请重新登录',
			duration: 1000,
			icon: 'none',
		});
		setTimeout(()=>{
			uni.reLaunch({
				url: '/pages/login/login'
			});
		}, 1000);
		return;
	}
}

/*
 * 请求对象 
 **/
app.requestObj = '';

/*
 * 终止请求 
 **/
app.requestAbort = function(){
	if(app.requestObj) app.requestObj.abort();
};

/*
 * 异步请求 
 **/
app.apiAsync = function(url, data, type = 'GET', token = ''){
	// let token = config.Access_token;
	// 检查token
	// app.checkToken(token);
	// let header = {
	// 	"Authorization": "Bearer " + token,
	// }
	let header = {
		"Content-Type" : "application/JSON"
	}
	
	if ( 
		url.indexOf('/dfApp/updatePasword') != -1 
		|| url.indexOf('/client/updateGetuiToken') != -1 
		|| url.indexOf('/dfApp/geTuiRecord') != -1 
		|| url.indexOf('/dfApp/getWaybillState') != -1 
		|| url.indexOf('/dfApp/getPromoteConfig') != -1 
		|| url.indexOf('/dfApp/geTuiUnreadMsg') != -1 
		|| url.indexOf('/dfApp/viewGeTuiMsg') != -1 
	) {
		header = {
			"Content-Type" : "application/JSON",
			"Authorization": token
		}
		data = JSON.stringify(data)
	}
	return new Promise((resolve, reject) => {
		uni.request({
			method: type,
			url: `${config.basePath}${url}`,
			data,
			header,
			success: (r) => {
                if ( r.data.code == 505 ) {
                    uni.reLaunch({
                    	url: '/pages/login/login'
                    })
                    return
                }
				resolve(r);
			},
			fail: (e) => {
				if(e.errMsg == 'request:fail abort') return;
				let r = { data: { code: -1 } };
				reject(r)
				uni.hideLoading();
				app.toast('网络错误11');
			}
		})
	})
	
	// return new Promise((resolve, reject) => {
	// 	uni.request({ 
	// 		url : `请求地址`,
	// 		method : "GET",
	// 		data : {},
	// 		success: (res) => {
	// 			console.log(res)
	// 			resolve('suc');  // 千万别忘写！！！
	// 		},
	// 		fail:(err)=>{
	// 			reject('err')
	// 		}
	// 	})
	// })
}

/*
 * 数据请求封装 
 * @param {String} url api链接
 * @param {Object} data 请求参数
 * @return {String} type 请求方式，默认“GET”
 * @return {Function} callback 回调
 **/
app.time = 3;
app.api = function(url, data, type, callback){
	let token = config.Access_token;
	// 检查token
	app.checkToken(token);
	
	let header = {
		"Authorization": "Bearer " + token,
	}
	
	// 兼容GET、POST
	let method = "GET";
	if(type == 'POST'){
		method = 'POST';
		if(
			url.indexOf('/act/myTask/handleTask') != -1 
			|| url.indexOf('/sys/system/user/updatePsw') != -1
			|| url.indexOf('/sixsys/flowSixSys/myApplications') != -1
			|| url.indexOf('/msg/msgDetial/msgSort') != -1
			|| url.indexOf('/hr/hrRyxp/submit') != -1
		){
			header = {
				"Authorization": "Bearer " + token,
				"Content-Type" : "application/x-www-form-urlencoded; charset=UTF-8"
			}
		}
	}else if(type == 'PUT'){
		method = 'PUT';
	}else if(type == 'DELETE'){
		method = 'DELETE';
	}else if(type == 'GET'){
		method = 'GET';
	}else{
		callback = type;
	}
	
	if(method == 'GET'){
		// ajax
		app.requestObj = uni.request({
			method: method,
			url: `${config.basePath}${url}`,
			data,
			header,
			success: (r) => {
				callback && callback(r)
			},
			fail: (e) => {
				if(e.errMsg == 'request:fail abort') return;
				let r = { data: { code: -1 } };
				callback && callback(r);
				uni.hideLoading();
				app.toast('网络错误');
			}
		});
	}else{
		if(app.time == 3){
			app.time = 0;
			app.requestObj = uni.request({
				method: method,
				url: `${config.basePath}${url}`,
				data,
				header,
				success: (r) => {
					callback && callback(r);
					let interval = setInterval(function(){
						app.time++;
						if(app.time >= 3){
							clearInterval(interval);
							app.time = 3;
						}
					}, 1000)
				},
				fail: (e) => {
					let interval = setInterval(function(){
						app.time++;
						if(app.time >= 3){
							clearInterval(interval);
							app.time = 3;
						}
					}, 1000)
					
					if(e.errMsg == 'request:fail abort') return;
					
					let r = { data: { code: -1 } };
					callback && callback(r);
					uni.hideLoading();
					app.toast('网络错误');
				}
			});
		}else{
			app.toast('请勿频繁提交');
			let interval = setInterval(function(){
				app.time = 3;
			}, 3000)
		}
	}
}

/*
 * 不做限制的POST数据请求封装 
 * @param {String} url api链接
 * @param {Object} data 请求参数
 * @return {Function} callback 回调
 **/
app.apiPost = function(url, data, method, callback){
	let token = config.Access_token;
	// 检查token
	app.checkToken(token);
	
	let header = {"Authorization": "Bearer " + token};
	
	if(
		url.indexOf('/sixsys/flowEcoDbdj/updateSuperviseStatus') != -1 
	){
		header = {
			"Authorization": "Bearer " + token,
			"Content-Type" : "application/x-www-form-urlencoded; charset=UTF-8"
		}
	}
	
	app.requestObj = uni.request({
		method: method,
		url: `${config.basePath}${url}`,
		data: data,
		header: header,
		success: (r) => {
			callback && callback(r)
		},
		fail: (e) => {
			if(e.errMsg == 'request:fail abort') return;
			let r = { data: { code: -1 } };
			callback && callback(r);
			uni.hideLoading();
			app.toast('网络错误');
		}
	});
}

/*
 * 吐司 
 * @param {String} title 标题
 **/
app.toast = function(title){
	uni.showToast({
		title: title,
		duration: 1000,
		icon: 'none'
	})
}

/*
 * 根据字典code,回显字典名称
 * @param {String} key 字典名
 * @param {Number} code 字典名的编号
 * @param {Function} callback 回调函数
 **/
app.dicName = function(key, code, callback){
	let token = config.Access_token;
	app.requestObj = uni.request({
		method: "GET",
		url: `${config.basePath}/sys/ser/serDictionary/selectDicByTypes/${key}`,
		data: {},
		header: {
			"Authorization" : "Bearer " + token
		},
		success: (r) => {
			r.data.data[0].serDictionaryList.map(item => {
				if(item.code == code) {
					callback && callback(item.name)
				};
			})
		},
		fail: (e) => {
			if(e.errMsg == 'request:fail abort') return;
			let r = { data: { code: -1 } };
			callback && callback(r);
			uni.hideLoading();
			app.toast('网络错误');
		}
	});
}

/* 
 * 根据日期计算年龄
 * @param {String} d 日期 2019-08-10
 **/
app.getAge = function(d){
	if(!d) return;
	let date = new Date();
	let nowYear = date.getFullYear();
	
	let year = d.split('-')[0];
	let age = nowYear - year;
	return age; 
}

/* 
 * @param {String} d 日期 2019-08-10
 **/
app.timeRemaining = function(d){
	if(!d) return;
	
	let date = new Date();
	let nowYear = date.getFullYear();
	let nowMuoth = date.getMonth() + 1;
	let nowDay = date.getDate();

	let T = new Date(nowYear, nowMuoth, nowDay, '00', '00', '00');
	let nowTime = T.getTime();
	
	let D = d.split('-');
	let endT = new Date(D[0], D[1], D[2], '00', '00', '00');
	let endTime = endT.getTime();

	let timeRemaining = (endTime - nowTime)/(24 * 60 * 60 * 1000)
	return timeRemaining;
}

/*
 * 用于文件前端生成uuid
 * @returns {string} uuid
 **/
app.getUuid = function() {
	let s = [];
	let hexDigits = "0123456789abcdef";
	for (let i = 0; i < 36; i++) {
		s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
	}
	s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
	s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
	s[8] = s[13] = s[18] = s[23] = "";

	let uuid = s.join("");
	return uuid;
}

/*
 * 图片上传 暂只支持单张上传
 * @param {Number} count 图片数量
 * @param {String} module 文件夹名
 * @param {String} insert insert：新增；update：更新
 * @param {String} uuid 附件标识
 * @param {Function} callback 回调函数
 * */
app.upLoad = function(path, module, insert, uuid, callback){
	let token = config.Access_token;
	// 检查token
	app.checkToken(token);
	
	if(!token) return;
	
	const uploadTask = uni.uploadFile({
		url : `${config.basePath}/file/fileStore/insert?dir=fileImage&&module=${module}&&moduleFunction=${insert}&&uuid=${uuid}`,
		header: {
			"Authorization" : "Bearer " + token
		},
		filePath: path[0],
		name: 'file',
		formData: {
			'user': 'wcy'
		},
		success: (r) => {
			callback && callback(r);
		}
	});
}

/*
 * 图片预览
 * @param {String/Array} path 图片路径
 * @param {Number} index 图片下标，默认第一张
 * */
app.previewImage = function(path, index){
	// 兼容数组、字符串
	if(typeof path == 'string'){
		path = [path];
	}
	
	// 默认第一张
	if(!index){
		index = 0;
	}
	uni.hideLoading();
	// 预览
	uni.previewImage({
		current: index,
		urls: path
	});
}

/*
 * 获取当前时间 Y-M-D H:M:S
 * return {String} Y-M-D H:M:S
 * */
app.formatDate = function(d) { 
	let now;
	if(!d) {now = new Date()} else {now = new Date(d)};
    let year = now.getFullYear(); 
    let month = now.getMonth()+1;
	month = month < 10 ? '0' + month : month;
    let date = now.getDate(); 
	date = date < 10 ? '0' + date : date;
    let hour = now.getHours(); 
	hour = hour < 10 ? '0' + hour : hour;
    let minute = now.getMinutes(); 
	minute = minute < 10 ? '0' + minute : minute;
    let second = now.getSeconds(); 
	second = second < 10 ? '0' + second : second;
    return year+"-"+month+"-"+date+" "+hour+":"+minute+":"+second; 
} 
/*
 * 时间转时间戳
 * @param {String} time 时间：Y-M-D / Y-M-D H:M:S
 * return {Number} t 时间戳
 */
app.getTimeStamp = function(time){
	time = time.replace(/-/g, '/');
	let t = (new Date(time)).getTime();
	return t;
}

/** 
 * json格式转树状结构 
 * @param   {json}   a   			//json数据 
 * @param   {String} idStr   		//id的字符串 
 * @param   {String} pidStr   		父id的字符串 
 * @param   {String} chindrenStr   	//children的字符串 
 * @return  {Array}     			数组 
 */
app.transData = function(a, idStr, pidStr, chindrenStr) {
    let r = [],
        hash = {},
        id = idStr,
        pid = pidStr,
        children = chindrenStr,
        i = 0,
        j = 0,
        len = a.length;
    for (; i < len; i++) {
        hash[a[i][id]] = a[i];
    }
    for (; j < len; j++) {
        let aVal = a[j],
            hashVP = hash[aVal[pid]];
        if (hashVP) {
            !hashVP[children] && (hashVP[children] = []);
            hashVP[children].push(aVal);
        } else {
            r.push(aVal);
        }
    }
    return r;
}

/* 
 * 获取文件
 * @param   {String}   uuid   附件uuid 
 * @return  {Array}    文件名数组 
 **/
app.getFiles = function(uuid, callback){
	app.api(`/file/fileStore/getByUuid/${uuid}`, {}, (r) => {
		callback && callback(r.data);
	})
}

/* 
 * 深拷贝
 * @param  {Object}   	obj   	
 * @return  {Object}  	result 	
 **/
app.deepCopy = function(obj) {
	let result = Array.isArray(obj) ? [] : {};
	for (let key in obj) {
		if (obj.hasOwnProperty(key)) {
			if (typeof obj[key] === 'object' && obj[key]!==null) {
				result[key] = deepCopy(obj[key]);
			} else {
				result[key] = obj[key];
			}
		}
	}
	return result;
}

/* 
 * 打开文件
 * @param  {String/Array} path 文件绝对地址
 * @param  {String} type isImage：图片，isFile：文件
 * @param  {Number} index 图片下标
 **/
app.previewFile = function(path, index){
	uni.showLoading({ title: "文件打开中..." });
	
	let type = 'isFile';
	if(app.isImg(path[index].url)) type = 'isImage';
	
	if(type == 'isImage'){
		let url = [], current;
		for(let i = 0; i < path.length; i++){
			if(app.isImg(path[i].url)){
				if(path[i].url.indexOf(config.actualIp) != -1 ){
					path[i].url = path[i].url.replace(config.actualIp, config.mappedIp);
				}
				/* 
					if(path[i].url.indexOf('30.129.3.20') != -1 ){
						path[i].url = path[i].url.replace('30.129.3.20', '192.168.14.16');
					} 
				**/
				url.push(path[i].url);
			}
		}
		for(let i = 0; i < url.length; i++){
			if(url[i] == path[index].url) current = i;
		}
		uni.hideLoading();

		uni.previewImage({ current: current, urls: url, indicator: 'default', loop: true });
	}else if(type == 'isFile'){
		path = path[index].url;
		path = path.indexOf(config.actualIp) != -1 ? path.replace(config.actualIp, config.mappedIp) : path;
		// path = path.indexOf('30.129.3.20') != -1 ? path.replace('30.129.3.20', '192.168.14.16') : path;
		uni.downloadFile({
			url: path,
			success: function (res) {
				let filePath = res.tempFilePath;
				uni.openDocument({
					filePath: filePath,
					success: function (res) {
						uni.hideLoading();
					}
				});
			},
			fail(e) {
				uni.hideLoading();
				app.toast('文件下载失败');
			}
		});
	}
}

/*
 * 是否为图片
 **/
app.isImg = function(str){
	let reg = /\.(bmp|jpg|jpeg|png|tif|gif|pcx|tga|exif|fpx|svg|psd|cdr|pcd|dxf|ufo|eps|ai|raw|WMF|webp|JPG|PNG)$/;
	return reg.test(str);
}

/*
 * 校验手机/座机
 * @param  {Number} val 手机或邮箱
 * @return {Boll} Boll
 **/
app.checkTel = function(val){
	let mobile = /^1[3|4|5|6|7|8|9]\d{9}$/,
		phone = /^0\d{2,3}-?\d{7,8}$/;
	if (!(mobile.test(val)) && !phone.test(val)) {
		return false;
	}else{
		return true;
	}
}

/*
 * 两位小数
 * @param  {Number} val 数值
 * @return {Number} val 数值
 **/
app.money = function(val){
	val = val.replace(/[^\d.]/g, "");
	val = val.replace(/\.{2,}/g, ".");
	val = val.replace(/^0+\./g, '0.');
	val = val.match(/^0+[1-9]+/) ? val = val.replace(/^0+/g, '') : val;
	val = (val.match(/^\d*(\.?\d{0,2})/g)[0]) || '';
	return val;
}

/*
 * 文件大小格式转换
 * @param  {Number} size 文件大小k
 * @return {String} num 文件大小KB/M/G
 **/
app.changeSize = function(size) {
	let num;
	if((size / 1024) <= 1024) {
		num = size / 1024;
		return num.toFixed(2) + 'KB';
	}
	if((size / 1024) > 1024 && (size / 1024) <= (1024 * 1024)) {
		num = (size / 1024) / 1024;
		return num.toFixed(2) + 'M';
	}
	if((size / 1024) > (1024 * 1024)) {
		num = ((size / 1024) / 1024) / 1024
		return num.toFixed(2) + 'G';
	}
}

/**
 * 获得对应的工作日日期
 * @param startDate   开始日期
 * @param dayCount    公示天数
 * @return {Function} cb 回调
 */
app.calcWeekdays = function(startDate, dayCount, cb){
	let days = [], 
		newHolidaies = [], 
		arr = [],
		newDate;
	
	let year = startDate.getFullYear();
	let month = (startDate.getMonth()+1) < 10 ? '0' + (startDate.getMonth()+1) : (startDate.getMonth()+1);
	let day = startDate.getDate() < 10 ? '0' + startDate.getDate() : startDate.getDate();
	startDate = Number(`${year}${month}${day}`);

	for (let i = 0; i < config.holidaies.length; i++) {
		newHolidaies.push(Number(config.holidaies[i]['holidayDate'].replace(/-/g, '')));
	}
	for(let i = 1; i < 13; i++) {
		newDate = new Date(year, i, 0);
		initDate(newDate.getMonth() + 1, newDate.getDate());
	};
	function initDate(M, D){
		if(M < 10) M = '0' + M;
		for(let i = 1; i < D + 1; i++) {
			if(i < 10) i = '0' + i;
			let str = Number(`${year}${M}${i}`);
			days.push(str);
		};
	}
	for(let i = 0; i < days.length; i++){
		if(days[i] >= startDate){
			for(let j = 0; j < newHolidaies.length; j++){
				if(days[i] == newHolidaies[j]){
				}else{
					if(!arr.includes(days[i]) && !newHolidaies.includes(days[i])) arr.push(days[i]);
					// 返回开始和结束时间
					if(arr.length == dayCount){
						// 结束日期
						let endYear = days[i].toString().substring(0, 4);
						let endMonth = days[i].toString().substring(4, 6);
						let endDate = days[i].toString().substring(6, 8);
						return cb && cb([year + '-' + month + '-' + day, endYear + '-' + endMonth + '-' + endDate])
					}
				}
			}
		}
	}
}

/*
 * 选择上传文件还是拍照
 **/
app.chooseType = function(){
	uni.showActionSheet({
		itemList: ['多图上传', '选择文件'],
		success: function (res) {
			switch(res.tapIndex){
				case 0: 
					uni.navigateTo({
						url: `/pages/comPages/uploadFile/camera`
					}) 
				break;
				case 1: 
					uni.navigateTo({
						url: `/pages/comPages/uploadFile/uploadFile`
					}) 
				break;
			}
		},
		fail: function (res) {
			console.log(res.errMsg);
		}
	});
}

/*
 * 处理base64\r\n问题
 * return {String} 处理后的base64
 **/
app.initBase64 = function(str){
	return str.replace(/(\r\n)|(\n)|(\r)/g, '');
}

/*
 * 计算N年后日期
 * @param {String} startdate 为开始时间 YYYY-MM-DD
 * @param {Number} nextYear 间隔年 nextYear年后
 * return {String} YYYY-MM-DD
 **/
app.getAfterNYear = function(startdate, nextYear){
	let oneYearTimes = 365 * 24 * 60 * 60 * 1000;
	let nowTime = new Date(startdate).getTime();
	let afterTime = new Date(nowTime + oneYearTimes * nextYear);
	let Y = afterTime.getFullYear();
	let M = afterTime.getMonth() + 1 < 10 ? ('0' + (afterTime.getMonth() + 1)) : (afterTime.getMonth() + 1);
	let D = afterTime.getDate() < 10 ? '0' + afterTime.getDate() : afterTime.getDate();
	return Y + '-' + M + '-' + D;
}

/*
 * 验证身份证信息
 * @param {String} idCardNum 身份证号码
 * @param {String} type 验证类型
 * return test： bool; birthday: 出所年月日； sex： 性别
 **/
app.IDcard = function(idCardNum, type){
	switch(type){
		case 'test':
			let sfzReg = /^[1-9]\d{5}(18|19|20|(3\d))\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;
			return sfzReg.test(idCardNum);
		break;
		case 'birthday':
			let birthday = "";
			if(idCardNum != null && idCardNum != ""){
				if(idCardNum.length == 15){
					birthday = "19" + idCardNum.slice(6,12);
				} else if(idCardNum.length == 18){
					birthday = idCardNum.slice(6,14);
				}	
				birthday = birthday.replace(/(.{4})(.{2})/,"$1-$2-");
			}	
			return birthday;
		break;
		case 'sex':
			let sexStr = '';
			if (parseInt(idCardNum.slice(-2, -1)) % 2 == 1) sexStr = '男';
			else sexStr = '女';
			return sexStr;
		break;
		
	}
}

/**
 * Js将数字转化为中文大写
 * @param {*} str 
 */
app.intToChinese = function(str){
	str = str + '';
	var len = str.length - 1;
	var idxs = ['', '拾', '佰', '仟', '万', '拾', '佰', '仟', '亿', '拾', '佰', '仟', '万', '拾', '佰', '仟', '亿'];
	var num = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖'];
	return str.replace(/([1-9]|0+)/g, function ($, $1, idx, full) {
		var pos = 0;
		if ($1[0] != '0') {
			pos = len - idx;
			if (idx == 0 && $1[0] == 1 && idxs[len - idx] == '拾') {
				return idxs[len - idx];
			}
			return num[$1[0]] + idxs[len - idx];
		} else {
			var left = len - idx;
			var right = len - idx + $1.length;
			if (Math.floor(right / 4) - Math.floor(left / 4) > 0) {
				pos = left - left % 4;
			}
			if (pos) {
				return idxs[pos] + num[$1[0]];
			} else if (idx + $1.length >= len) {
				return '';
			} else {
				return num[$1[0]]
			}
		}
	});
}

/**
 * 根据年月获取当月有多少天
 * @param {*} year 
 * @param {*} month 
 * @return {当月天数}
 */
app.getDaysInMonth = function(year, month) {
	month = parseInt(month, 10);
	let temp = new Date(year, month, 0);
	return temp.getDate();
}

/**
 * 输出年月日
 */
app.backDataByMonth = function(year,month,data) {
	var dataStr;
	if(month>12){//表示第二年
	    year = year + 1
	    month = month-12
	}
	if(data){
	    dataStr = `${year}-${month}-01`
	}else{
	    dataStr = `${year}-${month}-${app.getDaysInMonth(year,month)}`
	}
	return dataStr;
}

/**
 * 计算天数差的函数，通用 
 * @param {*} sDate1 结束时间2020-10-10
 * @param {*} sDate2 开始时间2020-10-9
 */
app.DateDiff = function(sDate1,  sDate2){ 
    var aDate, oDate1, oDate2,iDays;
        aDate  =  sDate1.split("-") 
        oDate1  =  new  Date(aDate[1]  +  '-'  +  aDate[2]  +  '-'  +  aDate[0])    //转换为12-18-2006格式 
        aDate  =  sDate2.split("-") 
        oDate2  =  new  Date(aDate[1]  +  '-'  +  aDate[2]  +  '-'  +  aDate[0]) 
        iDays  =  parseInt(Math.abs(oDate1  -  oDate2)  /  1000  /  60  /  60  /24)    //把相差的毫秒数转换为天数 
     return  iDays 
}

/**
* 时间格式化(返回年月日)
* fmt 传入的
*/
app.fmtDateYmd = function(obj) {
	let date = new Date(obj);
	let y = date.getFullYear();
	let m = date.getMonth() + 1;
	m = m < 10 ? ('0' + m) : m;
	let d = date.getDate();
	d = d < 10 ? ('0' + d) : d;
	return y + '-' + m + '-' + d;
}

/**
 * 时间格式化(返回年月)
 * fmt 传入的
 */
app.fmtDateYm = function(obj) {
	var date = new Date(obj);
	var y = date.getFullYear();
	var m = date.getMonth() + 1;
	m = m < 10 ? ('0' + m) : m;
	return y + '-' + m;
}
/**
 * 根据出生日期计算年龄
 * @param strBirthday
 * @returns {*}
 */
app.getAgeBirthday = function(strBirthday) {
	let returnAge;
	let strBirthdayArr = strBirthday.split("-");
	let birthYear = strBirthdayArr[0];
	let birthMonth = strBirthdayArr[1];
	let birthDay = strBirthdayArr[2];

	let d = new Date();
	let nowYear = d.getFullYear();
	let nowMonth = d.getMonth() + 1;
	let nowDay = d.getDate();

	if (nowYear == birthYear) {
		returnAge = 0; //同年 则为0岁
	} else {
		let ageDiff = nowYear - birthYear; //年之差
		if (ageDiff > 0) {
			if (nowMonth == birthMonth) {
				let dayDiff = nowDay - birthDay; //日之差
				if (dayDiff < 0) {
					returnAge = ageDiff - 1;
				} else {
					returnAge = ageDiff;
				}
			} else {
				let monthDiff = nowMonth - birthMonth; //月之差
				if (monthDiff < 0) {
					returnAge = ageDiff - 1;
				} else {
					returnAge = ageDiff;
				}
			}
		} else {
			returnAge = -1; //返回-1 表示出生日期输入错误 晚于今天
		}
	}
	return returnAge; //返回周岁年龄
}


export default app;